﻿package {
	
	
	import com.eclecticdesignstudio.motion.Equations;
	import com.eclecticdesignstudio.motion.GTweener;
	import com.eclecticdesignstudio.utils.FPSCounter;
	import com.gskinner.motion.GTween;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	
	
	/**
	 * @author Joshua Granick
	 */
	public class Example extends Sprite {
		
		
		private var FPS:FPSCounter;
		
		
		public function Example () {
			
			initialize ();
			
		}
		
		
		private function createCircle ():void {
			
			var circle:Sprite = new Sprite ();
			circle.graphics.beginFill (Math.random () * 0xFFFFFF);
			circle.graphics.drawCircle (0, 0, 50);
			
			circle.x = Math.random () * stage.stageWidth;
			circle.y = Math.random () * stage.stageHeight;
			
			circle.alpha = 0.25;
			
			addChild (circle);
			
			tweenCircle (circle);
			
		}
		
		
		private function initialize ():void {
			
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			FPS = new FPSCounter ();
			addChild (FPS);
			
			for (var i:uint = 0; i < 100; i++) {
				
				createCircle ();
				
			}
			
		}
		
		
		private function tweenCircle (circle:Sprite):void {
			
			var targetX:Number = Math.random () * stage.stageWidth;
			var targetY:Number = Math.random () * stage.stageHeight;
			
			GTweener.addTween (circle, 0.9, { x: targetX, y: targetY }, { ease: Equations.easeInOutExpo, completeListener: tweenCircle_onTweenComplete } );
			
		}
		
		
		
		
		// Event Handlers
		
		
		
		
		private function tweenCircle_onTweenComplete (event:Event):void {
			
			var tween:GTween = event.currentTarget as GTween;
			tweenCircle (tween.target as Sprite);
			
		}
		
		
	}
	
	
}